*********************************************************************************
* Figure 5, Footnote 4	 														*
*********************************************************************************

* Project: 	Stability of national identity
* Authors: 	Matthias Mader
* Date:		Feb 2023	

*********************************************************************************


*** Setup

	set more off            					// Disable partitioned output
	set dp period								// Use comma instead of dot for decimals
	set linesize 80         					// Line size limit to make output more readable
	macro drop _all         					// clear all macros
	set scheme plotplainblind					// set graph scheme
	graph set window fontface "Times New Roman" // set font 


*** Open data set

use "DATA_clean.dta", clear


*** Keep observations without missing values

	drop if ethnic21_cat1 == . | ///
	ethnic32_cat1 == . | ///
	ethnic43_cat1 == . | ///
	ethnic41_cat1 == . | ///
	civic21_cat1 ==. | ///
	civic32_cat1 == . | ///
	civic43_cat1 == . | ///
	civic41_cat1 == . | ///
	id21_cat1 == . | ///
	id32_cat1 == . | ///
	id43_cat1 == . | ///
	id41_cat1 == . | ///
	rwa21_cat1 == . | ///
	rwa32_cat1 == . | ///
	rwa43_cat1 == . | ///
	rwa41_cat1 == .


*** Figure 5: Predictors of intra-individual change
	sum ethnic_abs [aw = wei5_mz] // sample mean = 1.859136
	sum id1r ethnic1_extr [aw = wei5_mz], det // check percentiles

	reg ethnic_abs id1r ethnic1_extr i.id_type4 [pw = wei5_mz]
		margins, at(id1r=(.33 1)) at(ethnic1_extr=(0 1)) at(id_type4=(0 1))  post
	coefplot, ///
				name(g1, replace) ///
				xtitle("Predicted change", size(large)) xscale(range(.98 2.5)) xlabel(1 (.5) 2.5, labsize(large)) ///	
				ytitle(" ", size(large)) yscale(range(1 7)) ///
				ylabel(1 "National ID weak (t1)" 2 "National ID strong (t1)" 3 "Extremity low (t1)" 4 "Extremity high (t1)" ///
				5 "No structural ambivalence (t1)" 6 "Structural ambivalence (t1)", labsize(medlarge)) ///	
				title("Ehnic dimension", size(large)) ///
				xsize(4) ysize(3) ///
				xline(1.859136, lcolor(red)) ///
				text(6.6 1.9 "Sample average", color(red) place(right))


	sum civic_abs [aw = wei5_mz] // smaple mean = 1.337119
	sum id1r ethnic1_extr [aw = wei5_mz], det // check percentiles

	reg civic_abs id1r ethnic1_extr i.id_type4 [pw = wei5_mz]
		margins, at(id1r=(.33 1)) at(ethnic1_extr=(0 1)) at(id_type4=(0 1))  post
	coefplot, ///
				name(g2, replace) ///
				xtitle("Predicted change", size(large)) xscale(range(.98 2.5)) xlabel(1 (.5) 2.5, labsize(large)) ///	
				ytitle(" ", size(large)) yscale(range(1 7)) ///
				ylabel(1 "National ID weak (t1)" 2 "National ID strong (t1)" 3 "Extremity low (t1)" 4 "Extremity high (t1)" ///
				5 "No structural ambivalence (t1)" 6 "Structural ambivalence (t1)", labsize(medlarge)) ///	
				title("Civic dimension", size(large)) ///
				xsize(4) ysize(3) ///
				xline(1.337119, lcolor(red)) ///
				text(6.6 1.4 "Sample average", color(red) place(right))


*** Footnote 4 ("Individuals with medium attachment might hence show the highest variation in the answer distribution... However, this conjecture is not supported by the data.")
	reg ethnic_abs c.id1r##c.id1r ethnic1_extr i.id_type4 [pw = wei5_mz]
	margins, at(id1r=(0 (.1) 1)) post
	marginsplot
	reg civic_abs c.id1r##c.id1r ethnic1_extr i.id_type4 [pw = wei5_mz]
	margins, at(id1r=(0 (.1) 1)) post
	marginsplot

	egen tercile=xtile(id1r), n(3)
	tab id1r tercile
	reg ethnic_abs tercile ethnic1_extr i.id_type4 [pw = wei5_mz]
	reg civic_abs tercile ethnic1_extr i.id_type4 [pw = wei5_mz]
